# import necessary packages
import cv2 as cv
import numpy as np
import argparse

# construct the argument parser and parse the arguments
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True, help="The Path to Image")
args = vars(ap.parse_args())

# load the image and grab each channel: Red, Green, and Blue. It's
# import to note that Opencv stores an image as Nunpy array with
# its channels in reverse order! When we call cv2.split,we are
# actually getting the channels as Blue, Green, Red!
image = cv.imread(args["image"])
B, G, R = cv.split(image)

# show each channel indivdidually
cv.imshow("Red", R)
cv.imshow("Green", G)
cv.imshow("Blue", B)
cv.waitKey(0)

# merge the image back together again
merged = cv.merge([B, G, R])
cv.imshow("Merged", merged)
cv.waitKey(0)
cv.destroyAllWindows()

# visualize each channel in color
zeros = np.zeros(image.shape[:2], dtype="uint8")
cv.imshow("Red", cv.merge([zeros, zeros, R]))
cv.imshow("Green", cv.merge([zeros, G, zeros]))
cv.imshow("Blue", cv.merge([B, zeros, zeros]))
cv.waitKey(0)
